let cartTable=[{
	id:1,
	tradename:"飞利浦新安怡卡通企鹅杯学饮杯7安士200ml 训练水杯 防漏带手柄（2件装）",
	imgurl:"img/images/20150708112148lm2t0.jpg",
	price:"460",
	ischecked:false,
	num:1,
},
{
	id:2,
	tradename:"日本Merries花王新生儿纸尿裤S82",
	imgurl:"img/images/201509091748430829.jpg",
	price:"420",
	ischecked:false,
	num:1,

},
{
	id:3,
	tradename:"Sony/索尼 DSC-WX300",
	price:"490",
	imgurl:"img/images/3.jpg",
	ischecked:false,
	num:1,

},
{
	id:4,
	tradename:"韩国MOMMA手工陶瓷奶瓶（220ml,320ml）+保温夜光喂奶灯套装 多款颜色图案随机发货",
	imgurl:"img/images/201608081427026196.jpg",
	ischecked:false,
	price:"420",
	num:1,

}
]

		// 第二个组件中 即内容
        let ContentCom = {
			props:["item","k"],
			template:"#ContentCom",
			data:function(){
				return{
				 ischeck:this.item.ischecked
				}
			},
			watch:{
				"item.ischecked":function(newvalue){
					this.ischeck = newvalue;
					// console.log(this.ischeck);	
				},
				ischeck:function(newvalue){
					// console.log(newvalue);
					this.$emit("checkto",{k:this.k,ischeck:newvalue})
				}
			},
			methods:{
				add(key){
					// console.log(this.item);
					// this.item.num++
					this.$emit("add",key)
					// console.log(this.item.ischecked);
				},
				reduce(key){
					if(this.item.num>1){
						// this.item.num--
						this.$emit("reduce",key)
					}
				},
				del(key){
					this.$emit("del",this.item)
				},
			},

		}
        
		//实例化本身
		new Vue({
			el:"#app",
			components:{
                ContentCom,

			},
			data:{
				cartTable,
			},
			methods:{
				add(key){
					this.cartTable[key].num++;
				},
				reduce(key){
					this.cartTable[key].num--;
				},
				del(item){
					this.cartTable.splice(item,1)
				},
				checkto(obj){
					this.cartTable[obj.k].ischecked = obj.ischeck;
				},
				checkdel(){
					let res = this.cartTable.filter(item=>!item.ischecked);
					this.cartTable=res
				}
			},
			computed:{
				checkall:{
					get(){
						if(this.cartTable.length){
							return this.cartTable.every(item=>item.ischecked);
						}else{
							return false
						}
					},
					set(newvalue){
					this.cartTable.forEach(item=>{
							item.ischecked = newvalue;
						})
					}
				},
				totalnum(){
					let total = 0;
					this.cartTable.forEach(item=>{
						if(item.ischecked){
							total += item.num;
						}
					})
					return total;
				},
				totalPrice(){
					let total = 0;
					this.cartTable.forEach(item=>{
						if(item.ischecked){
							total += item.price*item.num;
						}
					})
					return total;
				},
			}

		})

		